package com.xiaohudie.Jedis;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;

/**
 * @Author xiao hu die
 * @Date 2022/2/28 19:32
 * @Version 1.0
 */
public class Test01 {
 private Jedis jedis;
 @BeforeEach
    void setUp(){
     /**建立连接*/
  //   jedis = new Jedis("112.124.39.228", 6379);
      jedis = JedisConnectionFactory.getJedis();

     /**选择库*/
     this.jedis.select(1);
 }
 @Test
    void testString(){
     /**存放数据*/
     String set = jedis.set("liudie520", "刘碟");
     System.out.println(set);
     /**取出数据*/
     String liudie = jedis.get("liudie");
     System.out.println(liudie);
 }
 @Test
 void testHash(){
     /**存数据*/
     jedis.hset("user:num:1","name","刘碟");
     jedis.hset("user:num:1","age","23");
     /*取数据*/
     String name = jedis.hget("user:num:1", "name");
     System.out.println(name);
 }
 @AfterEach
    void testClose(){
     if (jedis!=null){
         jedis.close();
     }
 }
}
